home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
330_03
/
tskdos.asm
< prev
next >
Wrap
Assembly Source File
|
1990-10-10
|
36KB
|
1,587 lines
;
; --- Version 2.2 90-10-12 10:37 ---
;
; CTask - DOS access module.
;
; Public Domain Software written by
; Thomas Wagner
; Ferrari electronic Gmbh
; Beusselstrasse 27
; D-1000 Berlin 21
; Germany
;
; NOTE: Some routines have been moved to "tsksec.asm" in Version 2.1
; to support a minimal secondary kernel.
;
; The support for the critical section interrupt was dropped in
; version 2.1. Swapping the DOS variable area eliminates
; the need for maintaining critical sections across calls.
;
; The DOS interrupt (and the related direct disk I/O interrupts) are
; not reentrant. Access to DOS thus has to be channelled such that no
; two tasks use DOS services simultaneously. However, there is one
; exception to this rule. Whenever DOS is waiting for the keyboard, it
; issues a special interrupt, INT 28h, to signal that background
; processing for functions > 0Ch may be performed. This is used in the
; DOS interface for CTask in the following manner:
;
; A task issuing a DOS interrupt will request one of two resources:
; "lower_dos" for functions <= 0C, "upper_dos" for functions > 0C.
; If a task gets access to "lower_dos", it will also request the
; "upper_dos" resource to lock out other tasks from interrupting.
; This "upper_dos" resource is shortly released on each INT 28, and
; then immediately reclaimed, with task priority temporarily raised
; to the maximum value. The first task waiting to execute a
; function > 0C will thus be scheduled to execute the request, but
; the resource will be reassigned to the INT 28 handler as soon as
; this request terminates, so the waiting task will not be delayed too
; long.
;
; There are two additional safety measures which have to be taken to
; avoid getting into conflicts with other resident background programs,
; especially the DOS PRINT background spooler:
;
; Before actually executing the request, the status of the DOS in-use
; flag is checked. If this flag is set, the task enters a busy waiting
; loop, calling the scheduler so that the processor is not tied up.
;
; NOTE: The method for checking the status of DOS is described in-depth
; in the book "The MS-DOS Encyclopedia" from Microsoft Press, in
; the chapter on TSR programming. The logic in this module was
; developed without the help of this book, so if you compare
; the code here with the routines in the Encyclopedia, you may
; notice that not all re-entry conditions are checked here.
; According to my experience with debugging TSR's and CTask, the
; logic should be sufficient for all but the most obscure TSR's.
; If you want to be completely on the safe side, you might consider
; adding the more thorough checks listed in the Encyclopedia.
;
; CAUTION: This module is not ROMable, and it can only be
; installed in the primary kernel.
;
name tskdos
;
include tsk.mac
;
IF DOS
;
.tsk_model
;
include tskdeb.h
;
Pubfunc tsk_install_dos
Pubfunc tsk_remove_dos
Pubfunc tsk_fatal
IF CHECKING
Pubfunc tsk_fatal_pmd
Globext tsk_set_currdis
Globext tsk_set_dualdis
Globext tsk_rputc
Globext tsk_rputs
Globext tsk_vrprintf
CGlbext tsk_rprintf
ENDIF
;
public tsk_emergency_exit
;
Globext create_resource
Globext delete_resource
Globext request_resource
Globext request_cresource
Globext release_resource
Globext create_flag
Globext delete_flag
Globext set_flag
Globext clear_flag
Globext wait_flag_clear
Globext yield
Globext preempt_off
;
Locext tsk_switch_stack
Locext tsk_old_stack
Locext tsk_remove_group
Locext tsk_kill_group
Locext tsk_remove_tasker
;
extrn tsk_instflags: word
;
extrn tsk_glob_rec: byte
IF NOT SINGLE_DATA
extrn tsk_global: dword
ENDIF
;
get_in_use_flag = 34h ; DOS-function to get in_use_flag address
get_invars = 5d06h ; DOS-function to get DOS-variables area
;
psp_offset = 10h-2 ; Offset of current PSP in DOS save area
; ; (-2 because we add 2 to the start)
;
; Structure of the start of a PSP, including undocumented fields
;
psp_record struc
;
dw ? ; INT 20
dw ? ; alloc block end
db ? ; reserved
db 5 dup(?) ; system call
psp_exit_addr dd ? ; exit routine address
psp_ctlc_addr dd ? ; control C routine address
psp_cerr_addr dd ? ; critical error routine address
parent_psp dw ? ; PSP of parent process
db 20 dup(?) ; files table
psp_envseg dw ? ; environment segment
psp_ustack dd ? ; ss/sp of caller
dw ? ; file table length
dd ? ; file table pointer
dd ? ; pointer to nested PSP (?)
;
psp_record ends
;
;
intseg segment at 0
org 10h*4
vidoff dw ? ; video interrupt
vidseg dw ?
org 13h*4
diskoff dw ? ; disk i/o interrupt
diskseg dw ?
org 20h*4
termoff dw ? ; program terminate vector
termseg dw ?
org 21h*4
idosoff dw ? ; dos interrupt
idosseg dw ?
org 25h*4
absreadoff dw ? ; absolute disk read
absreadseg dw ?
org 26h*4
abswriteoff dw ? ; absolute disk write
abswriteseg dw ?
org 27h*4
keepoff dw ? ; Terminate but stay resident
keepseg dw ?
org 28h*4
idleoff dw ? ; dos idle interrupt
idleseg dw ?
org 2ah*4
csectoff dw ? ; dos critical section
csectseg dw ?
org 40h*4
fdiskoff dw ? ; redirected floppy disk I/O interrupt
fdiskseg dw ?
;
intseg ends
;
;----------------------------------------------------------------------------
;
; Variables
;
.tsk_data
;
idle_active db 0 ; Idle-Interrupt active
dos310 db 0 ; DOS version >= 3.10
;
IF TSK_NAMEPAR
udos_name db "DOSUPPER",0
ldos_name db "DOSLOWER",0
hdio_name db "HARDDISK",0
fdio_name db "FLEXDISK",0
vid_name db "VIDEO",0
ENDIF
;
;
in_error dd ? ; Adress of DOS error-mode-flag
;
lower_dos resource <>
upper_dos resource <>
hdisk_io resource <>
fdisk_io resource <>
video resource <>
;
vid_flags dw ?
i13h_flags dw ?
i13f_flags dw ?
;
.tsk_edata
.tsk_code
;
;---------------------------------------------------------------------------
;
; Original Interrupt-Entries
;
savvid label dword ; original Video entry
savvidoff dw ?
savvidseg dw ?
;
savdisk label dword ; original Disk I/O entry
savdiskoff dw ?
savdiskseg dw ?
;
savfdisk label dword ; original Floppy Disk I/O entry
savfdiskoff dw ?
savfdiskseg dw ?
;
savtermoff dw ? ; Terminate vector save
savtermseg dw ?
;
savdos label dword ; original DOS-Entry
savdosoff dw ?
savdosseg dw ?
;
savidle label dword ; original IDLE-Entry
savidleoff dw ?
savidleseg dw ?
;
savcsect label dword ; Critical Section save
savcsectoff dw ?
savcsectseg dw ?
;
savabsread label dword ; Absolute Disk Read save
savabsreadoff dw ?
savabsreadseg dw ?
;
savabswrite label dword ; Absolute Disk Write save
savabswriteoff dw ?
savabswriteseg dw ?
;
savkeepoff dw ? ; Terminate resident vector save
savkeepseg dw ?
;
;
dos_version dw ? ; DOS version
;
temp_1 dw ?
;
tsk_dgroup dw @CTASK_DATA
;
zero db 0
;
calldos macro
pushf
cli
call cs:savdos
endm
;
;---------------------------------------------------------------------------
;
; void tsk_install_dos (void)
;
; Install DOS handler
;
Localfunc tsk_install_dos
;
; create needed resources & flags
;
IFDEF LOAD_DS
push ds
mov ax,@CTASK_DATA
mov ds,ax
ENDIF
;
IF TSK_NAMEPAR
callp create_resource,<<ds,#upper_dos>,<ds,#udos_name>>
ELSE
callp create_resource,<<ds,#upper_dos>>
ENDIF
;
IF TSK_NAMEPAR
callp create_resource,<<ds,#lower_dos>,<ds,#ldos_name>>
ELSE
callp create_resource,<<ds,#lower_dos>>
ENDIF
;
test tsk_instflags,IFL_DISK
jz inst_nodsk1
IF TSK_NAMEPAR
callp create_resource,<<ds,#hdisk_io>,<ds,#hdio_name>>
ELSE
callp create_resource,<<ds,#hdisk_io>>
ENDIF
;
IF TSK_NAMEPAR
callp create_resource,<<ds,#fdisk_io>,<ds,#fdio_name>>
ELSE
callp create_resource,<<ds,#fdisk_io>>
ENDIF
;
inst_nodsk1:
test tsk_instflags,IFL_VIDEO
jz inst_novid1
IF TSK_NAMEPAR
callp create_resource,<<ds,#video>,<ds,#vid_name>>
ELSE
callp create_resource,<<ds,#video>>
ENDIF
;
inst_novid1:
;
mov tsk_glob_rec.l_swap,0 ; init swap area length to 0
;
; Get the DOS version. Only v